package com.fafu.mybatis.demo.mapper;

import com.fafu.mybatis.demo.modal.UserInfo;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserInfoMapper {
//    @Select("select id, username, password, age, gender, phone,"
//            + "delete_flag as deleteFlag, create_time as createTime, update_time as updateTime from user_info")
    @Results(id = "BaseMap",value = {
             @Result(column = "delete_flag", property = "deleteFlag"),
             @Result(column = "create_time", property = "createTime"),
             @Result(column = "update_time", property = "updateTime")
            })

@Select("select id, username, password, age, gender, phone,"
        + "delete_flag, create_time, update_time from user_info")
    List<UserInfo> selectAll();

//    @ResultMap("BaseMap")
    @Select("select * from user_info")
    List<UserInfo> selectAll1();

    @Select("select * from user_info where id = #{id}")
    List<UserInfo> selectUserById(Integer id);

    @Select("select * from user_info where id = #{aa}")
    List<UserInfo> selectUserById1(Integer id);

    @Select("select * from user_info where age = #{age} and gender = #{gender}")
    List<UserInfo> selectUserByIdAndGender(Integer age,Integer gender);

    @Select("select * from user_info where age = #{age} and gender = #{gender}")
    List<UserInfo> selectUserByIdAndGender1(Integer gender,Integer age);

    @Select("select * from user_info where age = #{param2} and gender = #{param1}")
    List<UserInfo> selectUserByIdAndGender2(Integer gender,Integer age);

    @Select("select * from user_info where age = #{age1} and gender = #{gender1}")
    List<UserInfo> selectUserByIdAndGender3(@Param("gender1")Integer gender, @Param("age1") Integer age);

    @Insert("insert into user_info (username, `password`, age, gender)" + "value(#{username}, #{password}, #{age}, #{gender})")
    Integer insertUser(UserInfo userInfo);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user_info (username, `password`, age, gender)"
            + "value(#{userInfo.username}, #{userInfo.password}, #{userInfo.age}, #{userInfo.gender})")
    Integer insertUser1(@Param("userInfo") UserInfo userInfo);

    //删
    @Delete("delete from user_info where id= #{id}")
    Integer deleteUser(Integer id);

    @Delete("delete from user_info where id= #{id}")
    Integer deleteUser1(UserInfo userInfo);

    //改
    @Update("update user_info set password = #{password} where id =#{id}")
    Integer updateUser(UserInfo userInfo);

    @Select("select username, `password`, age, gender, phone from user_info where username = '${username}' ")
    UserInfo queryById(String username);

    @Select("select username, `password` from user_info where username = '${username}' and password = '${password}'")
    List<UserInfo> queryByUsernameAndPassword(String username,String password);

    //排序功能
    @Select("select * from user_info order by id ${order}")
    List<UserInfo> selectUserByOrder(String order);

    @Select("select * from user_info where username like CONCAT('%',#{name},'%')")
    List<UserInfo> selectUserByLike(String order);

}
